#include "xparameters.h"
#include "xgpio.h"
#include "stdio.h"
#include "xstatus.h"
#include "soundcode.h"

#define LED_DELAY       1000000
#define LED_CHANNEL     1
#define LED_MAX_BLINK   0x1     /* Number of times the LED Blinks */
#define GPIO_BITWIDTH   16      /* This is the width of the GPIO */
#define printf xil_printf       /* A smaller footprint printf */

void main() {
   SOUNDCODE_mWriteSlaveReg0(XPAR_SOUNDCODE_0_BASEADDR, SOUNDCODE_SLV_REG0_OFFSET, 1);
	int i;
	

	for (i = 100000; i > 20000; i = i - 5000) {
		SOUNDCODE_mWriteSlaveReg0(XPAR_SOUNDCODE_0_BASEADDR, SOUNDCODE_SLV_REG1_OFFSET, i);
		sleep_time_unit();
	}
	sleep_time_unit();
	sleep_time_unit();
	for (i = 20000; i < 100000; i = i + 5000) {
		SOUNDCODE_mWriteSlaveReg0(XPAR_SOUNDCODE_0_BASEADDR, SOUNDCODE_SLV_REG1_OFFSET, i);
		sleep_time_unit();
	}
	
	//SOUNDCODE_mWriteSlaveReg0(XPAR_SOUNDCODE_0_BASEADDR, SOUNDCODE_SLV_REG1_OFFSET, 90000);
	//sleep_time_unit();
   //SOUNDCODE_mWriteSlaveReg0(XPAR_SOUNDCODE_0_BASEADDR, SOUNDCODE_SLV_REG1_OFFSET, 30000);
	sleep_time_unit();
	SOUNDCODE_mWriteSlaveReg0(XPAR_SOUNDCODE_0_BASEADDR, SOUNDCODE_SLV_REG0_OFFSET, 0);
}

void sleep_time_unit() {
 printf("Sleep");
   int i = 0;
	for (i=0; i < 1500000; i++)
		asm("nop");
   printf("Finish");
 
}